﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WindowsAuthen
{

    public partial class getName : System.Web.UI.Page
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (HttpContext.Current.Request.IsAuthenticated)
                {
                   

                    var user = HttpContext.Current.Request.LogonUserIdentity.Name;
                    var u = new user { isLogin = true, domain = user.Split('\\')[0], name = user.Split('\\')[1], };
                    HttpContext.Current.Response.ContentType = "text/plain";
                    HttpContext.Current.Response.Write(serializer.Serialize(u));
                    HttpContext.Current.Response.End();
                    
                }
                else
                {
                    var u = new user { isLogin = false, name = string.Empty };
                    HttpContext.Current.Response.ContentType = "text/plain";
                    HttpContext.Current.Response.Write(serializer.Serialize(u));
                    HttpContext.Current.Response.End();
                }
            }
        }
    }
    public class user
    {
        public bool isLogin { get; set; }
        public string name { get; set; }
        public string domain { get; set; }
    }
}